<?php


/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program.  If not, see 
 * <http://www.gnu.org/licenses/>.
*/


// no direct access
defined('_JEXEC') or die('Restricted access');


jimport('joomla.application.component.view');


class GalleryViewImage extends JView
{
    function display($tpl = null)
    {
		global $mainframe, $option;

		$db     = JFactory::getDBO();
		$user   = JFactory::getUser();
		$model  = $this->getModel();
		$data   = $this->get('Data');

		$lists = array();

		// Fail if checked out not by 'me'.
		if ($model->isCheckedOut($user->get('id')))
		{
			$msg = JText::sprintf('DESCBEINGEDITTED', JText::_('Image'), $data->title);
			$mainframe->redirect('index.php?option='. $option, $msg);
			return;
		}
		
		if ($data->id > 0)
			$model->checkout($user->get('id'));
		else
		{
			$data = JRequest::getVar('catid', 0, 'post', 'int');
		}

		// build the html select list for ordering
		$query = 'SELECT ordering AS value, title AS text'
			. "\n	FROM #__gallery_images"
			. "\n	WHERE catid = $data->catid"
			. "\n	ORDER BY ordering"
			;
		$lists['ordering'] 	= JHTML::_('list.specificordering', $data, $data->id, $query, 1);

		// Build list of categories.
		$lists['catid']     = JHTML::_('list.category', 'catid', $option, $data->catid);
		// Build the html select list.
		$lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $dat->published);

		// Clean data for display.
		JFilterOutput::objectHTMLSafe($data, ENT_QUOTES);

		$this->assign('lists',  $lists);
		$this->assign('data',   $data);

        parent::display($tpl);
    }
}


?>
